package com.tianqu.tms.core.webservice;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TmsSqlUtil {
	Connection dbConn;  
	private void getsqlServer(){
		String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";   //加载JDBC驱动  
		 
	   String dbURL = "jdbc:sqlserver://192.168.3.9:1433; DatabaseName=mydb";   //连接服务器和数据库sample  
	 
	   String userName = "sa";   //默认用户名  
	 
	   String userPwd = "";   //密码  
   
	   try {  
		   
		   Class.forName(driverName);  
		 
		   dbConn = DriverManager.getConnection(dbURL, userName, userPwd);  
	   
		   System.out.println("Connection Successful!");   //如果连接成功 控制台输出Connection Successful!  
		 
		   } catch (Exception e) {  
		 
		   e.printStackTrace();  
		 
		   }  
	}
	
	public void insertSql(String licensePlate,String serial,String vin,String cardType,byte[] images ) throws SQLException{
		
		PreparedStatement ps = null;
		try {
			getsqlServer();			
			StringBuffer str = new StringBuffer();
			str.append(" INSERT INTO");
			str.append(" TABLE_1");
			str.append(" (");
			str.append(" ID,  ");
			str.append(" T1,  ");
			str.append(" T5,  ");
			str.append(" CAR_NUMBERTYPE,  ");
			str.append(" PHOTO  ");
			str.append(" )VALUES(  ");
			str.append("?,?,?,?,?");
			str.append(" )  ");
			ps = dbConn.prepareStatement(str.toString());
			ps.setString(1, serial);
			ps.setString(2, licensePlate);
			ps.setString(3, vin);
			ps.setString(4, cardType);
			ps.setBytes(5, images);

			ps.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			dbConn.close();
		}
		   
		
		
	}
	
}
